package com.drakulo.hi.gfx;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.UnicodeFont;

import com.dk.hi.core.Settings;

public class TextBox implements HIGraphicComponent {
	public static int WIDTH = Settings.WINDOW_WIDTH / 2;
	public static int HEIGHT = Settings.WINDOW_HEIGHT / 4;

	private static int X = Settings.WINDOW_WIDTH / 2 - (WIDTH / 2);
	private static int Y = Settings.WINDOW_HEIGHT / 2 - (HEIGHT / 2);

	private String text;
	private Button actionButton;

	public TextBox() {
		this.actionButton = Button.getOKButton();
		this.actionButton.setX(X + WIDTH - this.actionButton.getWidth() - 5);
		this.actionButton.setY(Y + HEIGHT - 20 - 5);
	}

	public boolean isToClose() {
		return this.actionButton.isOkClicked();
	}

	@Override
	public boolean mouseIsOnIt(int mouseX, int mouseY) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void render(Graphics g) throws SlickException {
		render(g, X, Y);
	}

	@Override
	public void render(Graphics g, int x, int y) throws SlickException {
		g.setColor(Color.gray);
		g.fillRect(x, y, WIDTH, HEIGHT);
		g.setColor(Color.black);
		g.drawRect(x, y, WIDTH, HEIGHT);

		UnicodeFont font = FontFactory.getDefaultFont();
		// FIXME Gérer les retours à la ligne et le nombre de lignes
		font.drawString(x + 20, y + 20, this.text);

		this.actionButton.render(g);
	}

	public void setText(String text) {
		this.text = text;
	}

	@Override
	public void update(Input input) {
		this.actionButton.update(input);
	}
}
